<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
<script>
let fsm = StateMachine.create({
  initial: 'off',
  events: [
    { name: 'buttonWasPressed', from: 'off', to: 'on' },
    { name: 'buttonWasPressed', from: 'on', to: 'off' },
  ],
  callback: {
    onbuttonWasPressed(event, from, to) {
      console.log(arguments);
    }
  },
  error(eventName, from, to, args, errorCode, errorMessage) {
    console.log(arguments);
  }
})
button.onclick = () => {
  fsm.buttonWasPressed();
}

let FSM = {
  walk: {
    attack() {
      console.log('攻击');
    },
    defense() {
      console.log('防御');
    },
    jump() {
      console.log('跳跃');
    },
  },
  attack: {
    walk() {
      console.log('攻击的时候不能行走');
    },
    defense() {
      console.log('攻击的时候不能防御');
    },
    jump() {
      console.log('攻击的时候不能跳跃');
    },
  }
}
</script> 
</body>
</html>